const BookListModule = require("../database/bookList");
const networkUtils = require("../utils/network");

// 获取所有书单
async function getBookList(req, res, next) {
  const originalData = await networkUtils.getData(
    req,
    res,
    next,
    BookListModule,
    { workMode: "return" }
  );
  const targetData = [];
  // 数据处理
  originalData.forEach((item) => {
    let isExist = false;
    targetData.forEach((itemy) => {
      if (itemy.book_list_id == item.book_list_id) {
        isExist = true;
      }
    });
    isExist ? "" : targetData.push(item);
  });
  targetData.forEach((item) => {
    item.cover = JSON.parse(item.cover);
  });
  res.status(200).json({
    msg: "查询成功",
    info: targetData,
  });
}

function getBookByBookListId(req, res, next) {
  networkUtils.getDataByOriginalSQL(req, res, next);
}

module.exports = {
  getBookList,
  getBookByBookListId,
};
